package wyh.service;

import org.apache.ibatis.session.SqlSession;
import wyh.mapper.ServiceRecordMapper;
import wyh.pojo.ServiceRecord;
import wyh.pojo.ServiceRecord2;
import wyh.util.MyBatisUtils;

import java.util.List;

public class ServiceRecordService {
    private static SqlSession sqlSession = null;
    private static ServiceRecordMapper serviceRecordMapper = null;

    public void beforeEach() {
        sqlSession = MyBatisUtils.getSession(true);
        serviceRecordMapper = sqlSession.getMapper(ServiceRecordMapper.class);
    }

    /**
     * @return 关联名字的查询输出222222
     */
    public List<ServiceRecord2> ServicegetAll2() {
        beforeEach();
        List<ServiceRecord2> serviceRecordList = serviceRecordMapper.MappergetAll2();
        sqlSession.close();
        return serviceRecordList;
    }

    public List<ServiceRecord> ServicegetAll() {
        beforeEach();
        List<ServiceRecord> serviceRecordList = serviceRecordMapper.MappergetAll();
        sqlSession.close();
        return serviceRecordList;
    }

    public Boolean ServicedeleteById(int serviceRecordId) {
        beforeEach();
        int result = serviceRecordMapper.MapperdeleteById(serviceRecordId);
        sqlSession.close();
        return result>0;
    }

    public Boolean Serviceupdate(ServiceRecord serviceRecord) {
        beforeEach();
        int result = serviceRecordMapper.MapperupdateById(serviceRecord);
        sqlSession.close();
        return result>0;
    }

    public Boolean Serviceadd(ServiceRecord serviceRecord) {
        beforeEach();
        int result = serviceRecordMapper.MapperaddServiceRecord(serviceRecord);
        sqlSession.close();
        return result>0;
    }

    public ServiceRecord ServicegetById(int serviceRecordId) {
        beforeEach();
        ServiceRecord serviceRecord = serviceRecordMapper.MappergetById(serviceRecordId);
        sqlSession.close();
        return serviceRecord;
    }
}